package com.csd.helper;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.vo.UserVO;

public class SessionManager {

	public static Integer getUserID() {
		HttpSession httpSession = ServletActionContext.getRequest()
				.getSession();
		UserVO value = (UserVO) httpSession.getAttribute(IConstant.userVO);
		if (value == null) {
			try {
//				throw new Exception("用户未登录异常");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		Integer id = value.getUserID();
		return id;
	}

	public static String getUserName() {
		HttpSession httpSession = ServletActionContext.getRequest()
				.getSession();
		UserVO value = (UserVO) httpSession.getAttribute(IConstant.userVO);
		if (value == null) {
			try {
//				throw new Exception("用户未登录异常");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		String name = value.getName();
		return name;
	}

	public static String getLoginName() {
		HttpSession httpSession = ServletActionContext.getRequest()
				.getSession();
		UserVO value = (UserVO) httpSession.getAttribute(IConstant.userVO);
		if (value == null) {
			try {
//				throw new Exception("用户未登录异常");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		String loginName = value.getLoginName();
		return loginName;
	}

	public static UserVO getUserVO() {
		HttpSession httpSession = ServletActionContext.getRequest()
				.getSession();
		UserVO value = (UserVO) httpSession.getAttribute(IConstant.userVO);
		if (value == null) {
			try {
//				throw new Exception("用户未登录异常");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return value;
	}

}
